//
//  ToolsVC.swift
//  ZJTools
//
//  Created by 万孟超 on 2023/10/26.
//

import Cocoa

class ToolsVC: NSViewController {
    
    lazy var viewModel = ToolVM()
    
    @IBOutlet weak var timeOutoutTextFiled: NSTextField!
    @IBOutlet weak var timeInputTextField: NSTextField!
    @IBOutlet weak var timeChangeSegment: NSSegmentedControl!
    
    @IBOutlet weak var colorSegment: NSSegmentedControl!
    
    @IBOutlet weak var bText: NSTextField!
    @IBOutlet weak var gtext: NSTextField!
    @IBOutlet weak var rText: NSTextField!
    @IBOutlet weak var hexText: NSTextField!
    
    @IBOutlet weak var viewNine: NSView!
    @IBOutlet weak var viewEight: NSView!
    @IBOutlet weak var viewSeven: NSView!
    @IBOutlet weak var viewSix: NSView!
    @IBOutlet weak var viewFive: NSView!
    @IBOutlet weak var viewFour: NSView!
    @IBOutlet weak var viewThree: NSView!
    @IBOutlet weak var viewTwo: NSView!
    @IBOutlet weak var viewOne: NSView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do view setup here.
        timeOutoutTextFiled.isEditable = true
        timeOutoutTextFiled.isSelectable = true
        
        
        timeInputTextField.isEditable = true
        timeInputTextField.isSelectable = true
        
        
        bText.isEditable = true
        bText.isSelectable = true
        gtext.isEditable = true
        gtext.isSelectable = true
        rText.isEditable = true
        rText.isSelectable = true
        hexText.isEditable = true
        hexText.isSelectable = true
        
        viewOne.wantsLayer = true
        viewOne.layer?.cornerRadius = 15
        viewOne.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.3).cgColor
        
        viewTwo.wantsLayer = true
        viewTwo.layer?.cornerRadius = 15
        viewTwo.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.3).cgColor
        
        viewThree.wantsLayer = true
        viewThree.layer?.cornerRadius = 15
        viewThree.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.3).cgColor
        
        viewFour.wantsLayer = true
        viewFour.layer?.cornerRadius = 15
        viewFour.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.3).cgColor
        
        viewFive.wantsLayer = true
        viewFive.layer?.cornerRadius = 15
        viewFive.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.3).cgColor
        
        viewSix.wantsLayer = true
        viewSix.layer?.cornerRadius = 15
        viewSix.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.3).cgColor
        
        viewSeven.wantsLayer = true
        viewSeven.layer?.cornerRadius = 15
        viewSeven.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.3).cgColor
        
        viewEight.wantsLayer = true
        viewEight.layer?.cornerRadius = 15
        viewEight.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.3).cgColor
        
        viewNine.wantsLayer = true
        viewNine.layer?.cornerRadius = 15
        viewNine.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.3).cgColor
    }
    
    @IBAction func timeExchangeAction(_ sender: NSButton) {
        do {
            timeOutoutTextFiled.stringValue = try viewModel.timeChange(timeChangeSegment.selectedSegment == 0 ? .timeInterval : .time, convert: timeInputTextField.stringValue)
        }catch ToolVM.TimeError.invalidInput(let errorText) {
            Alert.showAlert(message: errorText, sureTitle: "好的")
        }catch {
            
        }
    }
    
    @IBAction func colorChangeAction(_ sender: NSButton) {
        viewModel.colorChange(colorSegment.selectedSegment == 0 ? .ten : .hex, r: &rText.stringValue, g: &gtext.stringValue, b: &bText.stringValue, hex: &hexText.stringValue)
    }
    
}
